//package com.ugoodtech.mdcc.core.service.impl;
//
///* Copyright (C) Ugoodtech, Inc - All Rights Reserved
// * Unauthorized copying of this file, via any medium is strictly prohibited
// * Proprietary and confidential
// */
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.qiniu.common.QiniuException;
//import com.qiniu.common.Zone;
//import com.qiniu.http.Response;
//import com.qiniu.storage.Configuration;
//import com.qiniu.storage.UploadManager;
//import com.qiniu.util.Auth;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.PostConstruct;
//import java.io.IOException;
//import java.util.Map;
//
//@Service
//public class QiNiuService {
//    @Value("${qiniu.accessKey}")
//    private String accessKey;
//    @Value("${qiniu.secretKey}")
//    private String secretKey;
//    @Value("${qiniu.bucketName}")
//    private String bucketName;
//    @Value("${qiniu.bucketDomain}")
//    private String bucketDomain;
////    @Value("${qiniu.watermark}")
////    private String watermark;
//    private Auth auth;
//    private UploadManager uploadManager;
//
//    @PostConstruct
//    public void initAuth() {
//        Configuration cfg = new Configuration(Zone.zone1());
//        auth = Auth.create(accessKey, secretKey);
//        uploadManager = new UploadManager(cfg);
//    }
//
//    //简单上传，使用默认策略，只需要设置上传的空间名就可以了
//    public String getUpToken() {
//        System.out.print(bucketName);
//        return auth.uploadToken(bucketName);
//    }
//
//    public String upload(byte[] data) throws IOException {
//        try {
//            Response res = uploadManager.put(data, null, getUpToken());
//            ObjectMapper mapper = new ObjectMapper();
//            logger.debug("upload res:" + res.bodyString());
//            Map body = mapper.readValue(res.bodyString(), Map.class);
//            return (String) body.get("key");
//        } catch (QiniuException e) {
//            Response r = e.response;
//            logger.error(r.toString());
//            throw e;
//        }
//    }
//
////    public String getPublicDownloadUrl(String key) {
////        return "http://" + bucketDomain + "/" + key+ "?watermark/1/image/" + BaseUtil.getBase64(watermark)+"/gravity/Center/ws/0.45";
////    }
////
////    public String getNoWaterMarkPublicDownloadUrl(String key) {
////        return "http://" + bucketDomain + "/" + key+ "?watermark/1/image/" + BaseUtil.getBase64(watermark)+"/dissolve/1/ws/0";
////    }
////    public String getPublicDownloadUrl(String key) {
////        return "http://" + bucketDomain + "/" + key;
////    }
//
//    public String getPublicDownloadUrl(String key, Integer width, Integer height) {
//        return "http://" + bucketDomain + "/" + key + "?imageView2/1/w/" + width + "/h/" + height;
//    }
//
//    public String getPublicDownloadUrl(String key) {
//        return "http://" + bucketDomain + "/" + key ;
//    }
//
////    public String getDownloadUrl(String key) {
////        String url = "http://" + bucketDomain + "/" + key;
////        return auth.privateDownloadUrl(url, 3600 * 24 * 7);
////    }
//
////    public String getDownloadUrl(String key, Integer width, Integer height) {
////        String url = "http://" + bucketDomain + "/" + key + "?imageView2/1/w/" + width + "/h/" + height;
////        return auth.privateDownloadUrl(url, 3600*24*7);
////    }
//
//    Logger logger = LoggerFactory.getLogger(QiNiuService.class);
//}